/*
 * Filename:    HcpmsWarnController.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014年11月6日
 */
package com.paic.mhis.hcpms.warning.web.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.paic.mhis.core.auth.biz.service.Authority;
import com.paic.mhis.core.auth.biz.service.UserDetails;
import com.paic.mhis.hcpms.agreement.healthcareprovider.util.HttpProcessUtil;
import com.paic.mhis.hcpms.audit.biz.service.ProblemNoticeService;
import com.paic.mhis.hcpms.common.storage.biz.service.HcpmsStorageService;
import com.paic.mhis.hcpms.common.storage.dto.HcpmsStorageDTO;
import com.paic.mhis.hcpms.common.workflow.vo.HcpmsWorkFlowVO;
import com.paic.mhis.hcpms.trust.biz.service.IntegrityMedicalService;
import com.paic.mhis.hcpms.warning.biz.service.HcpmsWarnService;
import com.paic.mhis.hcpms.warning.biz.service.WarningWorkFlowService;
import com.paic.mhis.hcpms.warning.dto.HcpmsWarnProcessInfoDTO;
import com.paic.mhis.hcpms.warning.dto.HcpmsWarningDTO;
import com.paic.mhis.hcpms.warning.dto.HcpmsWarnsDTO;
import com.paic.mhis.hcpms.warning.dto.WarnResultDTO;
import com.paic.mhis.hcpms.warning.dto.WarningCheckDetailDTO;
import com.paic.mhis.hcpms.warning.dto.WarningGtasksDTO;
import com.paic.mhis.hcpms.warning.util.WarnConstants;
import com.paic.pafa.appclient.annotation.BizServicesProxy;
import com.paic.pafa.exceptions.BusinessException;

@Controller
@RequestMapping("/hcpmsWarning/")
public class HcpmsWarnController {
	@BizServicesProxy
	private HcpmsWarnService hcpmsWarnService;
	@BizServicesProxy
	private WarningWorkFlowService warningWorkFlowService;
	@BizServicesProxy
	private HcpmsStorageService hcpmsStorageService;// 暂存的服务层

	@BizServicesProxy(beanName = "integrityMedicalService")
	private IntegrityMedicalService integrityMedicalService;

	@BizServicesProxy(beanName = "problemNoticeService")
	public ProblemNoticeService problemNoticeService;

	@BizServicesProxy(beanName = "hcpmsStorageService")
	HcpmsStorageService storageService;

	/***
	 * 保存预警事件
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "saveWarning.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> saveWarning(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		// 获取参数
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		String str = HttpProcessUtil.readRequestBody(request);
		JSONObject transferJson = JSON.parseObject(str);
		String warnNo = transferJson.getString("warnNo");
		String status = transferJson.getString("status");
		// 操作权限的绑定和查询操作权限
		if (StringUtils.hasText(warnNo) && StringUtils.hasText(status)) {
			String processState = warningWorkFlowService.vilidateOrBindUser(warnNo, user.getUsername(), status);
			if (WarnConstants.PROCESS_NOT_POWER.endsWith(processState)) {
				result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
				result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_NOT_POWER_ERROR);
				return result;
			} else if (WarnConstants.PROCESS_OUT_POWER.endsWith(processState)) {
				result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
				result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_OUT_POWER_ERROR);
				return result;
			}
		}
		HcpmsWarningDTO dto = new HcpmsWarningDTO();
		// 是否进行暂存操作
		if ((!StringUtils.hasText(status)) || WarnConstants.WARN_STATUS_1.equals(status)
				|| WarnConstants.WARN_STATUS_2.equals(status) || WarnConstants.WARN_STATUS_3.equals(status)) {
			try {
				result = hcpmsWarnService.editHcpmsWarn(transferJson.getJSONObject("warnInfo"), user.getUsername(),
						warnNo);
			} catch (Exception e) {
				result = HttpProcessUtil.processException(e);
				return result;
			}
			if (result.isEmpty()
					&& !(transferJson.getJSONObject("warnInfo") == null || transferJson.getJSONObject("warnInfo")
							.size() <= 0)) {
				result.put(WarnConstants.MSG_KEY, WarnConstants.SAVE_DOUBLE);
				return result;
			}
			dto = (HcpmsWarningDTO) result.get("warnInfo");
			result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONObject("medicalInfo"),
					user.getUsername(), dto.getWarnNo(), WarnConstants.TARGET_TYPE_MEDICAL);
			result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONArray("staffList"), user.getUsername(),
					dto.getWarnNo(), WarnConstants.TARGET_TYPE_STAFF);
			result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONArray("insurList"), user.getUsername(),
					dto.getWarnNo(), WarnConstants.TARGET_TYPE_INSURANCE);

			result = hcpmsWarnService.editHcpmsWarnScreen(transferJson.getJSONArray("screenList"), user.getUsername(),
					dto.getWarnNo());
			result = hcpmsWarnService.editHcpmsWarnNotice(transferJson.getJSONObject("notice"), user.getUsername(),
					dto.getWarnNo(), WarnConstants.TASK_TYPE_WARNING, WarnConstants.DOC_TYPE_NOTICE);
			try {

				if (StringUtils.hasText(warnNo)) {
					integrityMedicalService.addIntegrityPointTemps(transferJson, user.getUsername());// 临时扣分
				} else {
					warnNo = dto.getWarnNo();
					// 扣分
					integrityMedicalService.addIntegrityPoints(transferJson, user.getUsername(), dto.getWarnNo(), "01");
				}

			} catch (Exception e) {
				if (!StringUtils.hasText(warnNo)) {
					warnNo = dto.getWarnNo();
				}
			}
		} else {
			// 进行暂存操作
			result = hcpmsWarnService.editStorageSave(transferJson, warnNo, user.getUsername());
		}
		try {
			// 启动
			Map<String, String> condition = new HashMap<String, String>();
			if (dto != null && StringUtils.hasText(dto.getSource())) {
				condition.put("SOURCE", dto.getSource());
			}
			String actCurrent = warningWorkFlowService.startWorkFlow(warnNo, user, condition);
			// 更新状态
			HcpmsWarningDTO warnDto = new HcpmsWarningDTO();
			warnDto.setWarnNo(warnNo);
			warnDto.setUpdatedBy(user.getUsername());
			warnDto.setStatus(actCurrent);
			hcpmsWarnService.updateHcpmsWarn(warnDto);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
		result.put(WarnConstants.MSG_KEY, WarnConstants.SAVE_SUCCESS);
		result.put(WarnConstants.RESULT_BUSINESS_WARN_KEY, warnNo);
		return result;
	}

	/***
	 * 提交流程预警事件
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "submitWarnProcess.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> submitWarnProcess(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		// 获取参数
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		String str = HttpProcessUtil.readRequestBody(request);
		JSONObject transferJson = JSON.parseObject(str);
		String warnNo = transferJson.getString("warnNo");
		String status = transferJson.getString("status");// 预警表中状态字段:待审批，待审核等
		if (StringUtils.hasText(status) && StringUtils.hasText(warnNo)) {
			String processState = warningWorkFlowService.vilidateOrBindUser(warnNo, user.getUsername(), status);// 获取操作权限级别(0:有操作权限;1没有操作权限
																												// 2：操作节点已变更)
			if (WarnConstants.PROCESS_NOT_POWER.endsWith(processState)) {// 如果操作权限级别是：流程节点已变更
				result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);// 返回成功的状态
				result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_NOT_POWER_ERROR);// 提示处理节点已变更
				return result;
			} else if (WarnConstants.PROCESS_OUT_POWER.endsWith(processState)) {// 如果操作权限级别是：没有操作权限
				result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
				result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_OUT_POWER_ERROR);// 提示同组其他人员已经对其进行操作!
				return result;
			}
		}
		// 如果预警表中预警任务编号或状态为空
		try {
			result = hcpmsWarnService.editHcpmsWarn(transferJson.getJSONObject("warnInfo"), user.getUsername(), warnNo);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
			return result;
		}
		if (result.isEmpty()) {
			result.put(WarnConstants.MSG_KEY, WarnConstants.SAVE_DOUBLE);// 返回消息标志：预警编号重复
			return result;
		}
		HcpmsWarningDTO dto = (HcpmsWarningDTO) result.get("warnInfo");

		if (!StringUtils.hasText(warnNo)) {
			warnNo = dto.getWarnNo();
		}
		result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONObject("medicalInfo"), user.getUsername(),
				warnNo, WarnConstants.TARGET_TYPE_MEDICAL);
		result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONArray("staffList"), user.getUsername(),
				warnNo, WarnConstants.TARGET_TYPE_STAFF);
		result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONArray("insurList"), user.getUsername(),
				warnNo, WarnConstants.TARGET_TYPE_INSURANCE);

		result = hcpmsWarnService.editHcpmsWarnScreen(transferJson.getJSONArray("screenList"), user.getUsername(),
				warnNo);
		result = hcpmsWarnService.editHcpmsWarnNotice(transferJson.getJSONObject("notice"), user.getUsername(), warnNo,
				WarnConstants.TASK_TYPE_WARNING, WarnConstants.DOC_TYPE_NOTICE);// 保存或更改文档实体表
		// 扣分
		integrityMedicalService.addIntegrityPoints(transferJson, user.getUsername(), warnNo, "01");
		// 启动
		try {
			Map<String, String> condition = new HashMap<String, String>();
			condition.put("SOURCE", dto.getSource());// 将预警表中的预警来源存放到map中
			String actCurrent = warningWorkFlowService.startWorkFlow(warnNo, user, condition);// 获取启动流程的当前节点
			// 提交
			HcpmsWorkFlowVO wfvo = new HcpmsWorkFlowVO();
			wfvo.setTaskNo(warnNo);// 设置任务启动Id
			wfvo.setActCurrent(user.getUsername());// 将当前处理人Id设为当前登录者的用户名
			actCurrent = warningWorkFlowService.processWorkFlow(wfvo);// 获取流转流程的当前节点
			// 更新状态
			HcpmsWarningDTO warnDto = new HcpmsWarningDTO();
			warnDto.setWarnNo(warnNo);
			warnDto.setUpdatedBy(user.getUsername());
			warnDto.setStatus(actCurrent);
			hcpmsWarnService.updateHcpmsWarn(warnDto);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
		result.put(WarnConstants.MSG_KEY, WarnConstants.SAVE_SUCCESS);
		return result;
	}

	/***
	 * 审核预警事件
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "auditWarnProcess.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> auditWarn(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();

		// 获取参数
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		String str = HttpProcessUtil.readRequestBody(request);
		JSONObject transferJson = JSON.parseObject(str);
		integrityMedicalService.addIntegrityPointTemps(transferJson, user.getUsername());// 临时扣分
		String warnNo = transferJson.getString("warnNo");
		String status = transferJson.getString("status");
		if (StringUtils.hasText(warnNo) && StringUtils.hasText(status)) {
			String processState = warningWorkFlowService.vilidateOrBindUser(warnNo, user.getUsername(), status);
			if (WarnConstants.PROCESS_NOT_POWER.endsWith(processState)) {
				result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
				result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_NOT_POWER_ERROR);
				return result;
			} else if (WarnConstants.PROCESS_OUT_POWER.endsWith(processState)) {
				result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
				result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_OUT_POWER_ERROR);
				return result;
			}
		}
		try {
			result = hcpmsWarnService.editHcpmsWarn(transferJson.getJSONObject("warnInfo"), user.getUsername(), warnNo);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
			return result;
		}
		HcpmsWarningDTO dto = (HcpmsWarningDTO) result.get("warnInfo");
		if (!StringUtils.hasText(warnNo)) {
			warnNo = dto.getWarnNo();
		}
		result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONObject("medicalInfo"), user.getUsername(),
				warnNo, WarnConstants.TARGET_TYPE_MEDICAL);
		result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONArray("staffList"), user.getUsername(),
				warnNo, WarnConstants.TARGET_TYPE_STAFF);
		result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONArray("insurList"), user.getUsername(),
				warnNo, WarnConstants.TARGET_TYPE_INSURANCE);

		result = hcpmsWarnService.editHcpmsWarnScreen(transferJson.getJSONArray("screenList"), user.getUsername(),
				warnNo);
		result = hcpmsWarnService.editHcpmsWarnNotice(transferJson.getJSONObject("notice"), user.getUsername(), warnNo,
				WarnConstants.TASK_TYPE_WARNING, WarnConstants.DOC_TYPE_NOTICE);
		try {
			HcpmsWarningDTO warnDto = new HcpmsWarningDTO();
			HcpmsWorkFlowVO wfvo = new HcpmsWorkFlowVO();
			wfvo.setTaskNo(warnNo);
			wfvo.setActCurrent(user.getUsername());
			Map<String, String> condition = new HashMap<String, String>();
			if (WarnConstants.WARN_PROCESS_BACK.equals(dto.getAuditOpinion())) {
				wfvo.setAssigner(dto.getAgent());
				condition.put("AUDIT_OPINION", dto.getAuditOpinion());
			} else {
				if (WarnConstants.WARN_PROCESS_TYPE_03.equals(dto.getProcess())
						|| WarnConstants.WARN_PROCESS_TYPE_05.equals(dto.getProcess())) {
					condition.put("PROCESS_TYPE", dto.getProcess());
				} else {
					condition.put("AUDIT_OPINION", dto.getAuditOpinion());
					warnDto.setIsFeedback(WarnConstants.WARN_ISFEEDBACK_01);
				}
			}
			wfvo.setParamValue(condition);
			String actCurrent = warningWorkFlowService.processWorkFlow(wfvo);
			// 更新状态
			warnDto.setWarnNo(warnNo);
			warnDto.setUpdatedBy(user.getUsername());
			warnDto.setStatus(actCurrent);
			hcpmsWarnService.updateHcpmsWarn(warnDto);
			if ("N2014009".equals(actCurrent) && WarnConstants.WARN_PROCESS_TYPE_03.equals(dto.getProcess())) {
				hcpmsWarnService.warningChangeAudit(warnNo);
				problemNoticeService.notice();
			}
			hcpmsWarnService.deleteStorageDateAll(warnNo, null);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
		result.put(WarnConstants.MSG_KEY, WarnConstants.SAVE_SUCCESS);
		return result;
	}

	/***
	 * 自查结论评估
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "assessResultWarin.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> assessSelfResult(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			// 获取参数
			UserDetails user = (UserDetails) request.getSession().getAttribute("user");
			String str = HttpProcessUtil.readRequestBody(request);
			JSONObject transferJson = JSON.parseObject(str);
			String warnNo = transferJson.getString("warnNo");
			String status = transferJson.getString("status");
			String feedbackEndDate = transferJson.getString("feedbackEndDate");
			if (StringUtils.hasText(status) && StringUtils.hasText(warnNo)) {
				String processState = warningWorkFlowService.vilidateOrBindUser(warnNo, user.getUsername(), status);
				if (WarnConstants.PROCESS_NOT_POWER.endsWith(processState)) {
					result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
					result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_NOT_POWER_ERROR);
					return result;
				} else if (WarnConstants.PROCESS_OUT_POWER.endsWith(processState)) {
					result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
					result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_OUT_POWER_ERROR);
					return result;
				}
			}
			integrityMedicalService.addIntegrityPointTemps(transferJson, user.getUsername());// 临时扣分
			String opinion = transferJson.getString("opinion");
			result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONArray("staffList"), user.getUsername(),
					warnNo, WarnConstants.TARGET_TYPE_STAFF);
			result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONArray("insurList"), user.getUsername(),
					warnNo, WarnConstants.TARGET_TYPE_INSURANCE);
			result = hcpmsWarnService.editAssessResultList(transferJson.getJSONArray("assessResultList"),
					user.getUsername(), warnNo);
			result = hcpmsWarnService.editAssessResult(transferJson.getJSONObject("assessResult"), user.getUsername(),
					warnNo);
			result = hcpmsWarnService.editHcpmsWarnNotice(transferJson.getJSONObject("resultNotice"),
					user.getUsername(), warnNo, WarnConstants.TASK_TYPE_WARNING, WarnConstants.DOC_TYPE_TOLD);
			// 启动
			HcpmsWorkFlowVO wfvo = new HcpmsWorkFlowVO();
			List<Authority> authorityList = user.getAuthorities();
			List<String> role = new ArrayList<String>();
			for (Authority authority : authorityList) {
				role.add(authority.getAuthority());
			}
			wfvo.setRole(role);
			wfvo.setTaskNo(warnNo);
			Map<String, String> condition = new HashMap<String, String>();

			if (StringUtils.hasText(feedbackEndDate)) {

				long currentTime = new Date().getTime();

				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

				Date feedbackDate = format.parse(feedbackEndDate);

				long feedBackLong = feedbackDate.getTime();

				if (currentTime > feedBackLong && !WarnConstants.WARN_CHECK_AUDIT_RESULT_OK.equals(opinion)) {
					opinion = WarnConstants.WARN_CHECK_AUDIT_RESULT_OK;
				}

			}

			condition.put("SITUATION", opinion);
			wfvo.setParamValue(condition);
			String actCurrent = warningWorkFlowService.processWorkFlow(wfvo);
			// 更新状态
			HcpmsWarningDTO warnDto = new HcpmsWarningDTO();
			warnDto.setWarnNo(warnNo);
			warnDto.setUpdatedBy(user.getUsername());
			warnDto.setStatus(actCurrent);
			if (!WarnConstants.WARN_CHECK_AUDIT_RESULT_OK.equals(opinion)) {
				warnDto.setIsFeedback(WarnConstants.WARN_ISFEEDBACK_01);
				String isCheckBack = transferJson.getString("isCheckBack");
				if (StringUtils.hasText(isCheckBack)) {
					warnDto.setIsCheckBack(isCheckBack);
				}
			}
			hcpmsWarnService.updateHcpmsWarn(warnDto);
			hcpmsWarnService.deleteStorageDateAll(warnNo, null);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
		result.put(WarnConstants.MSG_KEY, WarnConstants.SAVE_SUCCESS);
		return result;
	}

	/***
	 * 结论审核/复审意见
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "resultAuditProcess.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> resultAudit(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			// 获取参数
			UserDetails user = (UserDetails) request.getSession().getAttribute("user");
			String str = HttpProcessUtil.readRequestBody(request);
			JSONObject transferJson = JSON.parseObject(str);
			String warnNo = transferJson.getString("warnNo");
			String status = transferJson.getString("status");
			if (StringUtils.hasText(warnNo) && StringUtils.hasText(status)) {
				String processState = warningWorkFlowService.vilidateOrBindUser(warnNo, user.getUsername(), status);
				if (WarnConstants.PROCESS_NOT_POWER.endsWith(processState)) {
					result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
					result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_NOT_POWER_ERROR);
					return result;
				} else if (WarnConstants.PROCESS_OUT_POWER.endsWith(processState)) {
					result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
					result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_OUT_POWER_ERROR);
					return result;
				}
			}
			integrityMedicalService.addIntegrityPointTemps(transferJson, user.getUsername());// 临时扣分
			String opinion = transferJson.getString("opinion");
			String beforePerson = transferJson.getString("beforePerson");
			result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONArray("staffList"), user.getUsername(),
					warnNo, WarnConstants.TARGET_TYPE_STAFF);
			result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONArray("insurList"), user.getUsername(),
					warnNo, WarnConstants.TARGET_TYPE_INSURANCE);
			// 保存
			result = hcpmsWarnService.editWarnResultAudit(transferJson.getJSONObject("auditResult"),
					user.getUsername(), warnNo);
			result = hcpmsWarnService.editHcpmsWarnNotice(transferJson.getJSONObject("resultNotice"),
					user.getUsername(), warnNo, WarnConstants.TASK_TYPE_WARNING, WarnConstants.DOC_TYPE_TOLD);
			// 启动
			HcpmsWorkFlowVO wfvo = new HcpmsWorkFlowVO();
			List<Authority> authorityList = user.getAuthorities();
			List<String> role = new ArrayList<String>();
			for (Authority authority : authorityList) {
				role.add(authority.getAuthority());
			}
			wfvo.setRole(role);
			wfvo.setTaskNo(warnNo);
			Map<String, String> condition = new HashMap<String, String>();
			condition.put("AUDIT_OPINION", opinion);
			if (!WarnConstants.WARN_PROCESS_NEXT.equals(opinion)) {
				wfvo.setActCurrent(beforePerson);
			}
			wfvo.setParamValue(condition);
			String actCurrent = warningWorkFlowService.processWorkFlow(wfvo);

			// 更新状态
			HcpmsWarningDTO warnDto = new HcpmsWarningDTO();
			warnDto.setWarnNo(warnNo);
			warnDto.setUpdatedBy(user.getUsername());
			warnDto.setStatus(actCurrent);
			String isCheckBack = transferJson.getString("isCheckBack");
			if (StringUtils.hasText(isCheckBack)) {
				warnDto.setIsCheckBack(isCheckBack);
			}
			hcpmsWarnService.updateHcpmsWarn(warnDto);
			hcpmsWarnService.deleteStorageDateAll(warnNo, null);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
		result.put(WarnConstants.MSG_KEY, WarnConstants.SAVE_SUCCESS);
		return result;
	}

	/**
	 * 预警事件的审批
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "warnApproveAudit.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> warnApproveAudit(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			// 获取参数
			UserDetails user = (UserDetails) request.getSession().getAttribute("user");
			String str = HttpProcessUtil.readRequestBody(request);
			JSONObject transferJson = JSON.parseObject(str);
			String warnNo = transferJson.getString("warnNo");
			String status = transferJson.getString("status");
			if (StringUtils.hasText(warnNo) && StringUtils.hasText(status)) {
				String processState = warningWorkFlowService.vilidateOrBindUser(warnNo, user.getUsername(), status);// 获取操作权限级别(0:有操作权限;1没有操作权限
																													// 2：操作节点已变更)
				if (WarnConstants.PROCESS_NOT_POWER.endsWith(processState)) {// 如果流程节点已变更
					result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
					result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_NOT_POWER_ERROR);// 提示处理的节点已经变更!
					return result;
				} else if (WarnConstants.PROCESS_OUT_POWER.endsWith(processState)) {// 如果没有操作权限
					result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
					result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_OUT_POWER_ERROR);// 提示同组其他人员已经对其进行操作!
					return result;
				}
			}
			// ===============================================================================================
			// 预警任务编号为空或预警状态为空或有权限操作
			integrityMedicalService.addIntegrityPointTemps(transferJson, user.getUsername());// 临时扣分
			String beforePerson = transferJson.getString("beforePerson");// 获取审批前的审核人：warnsh
			try {
				result = hcpmsWarnService.editHcpmsWarn(transferJson.getJSONObject("warnInfo"), user.getUsername(),
						warnNo);// 根据预警实体类等信息修改预警表(为预警表设置审核人和审核时间)
			} catch (Exception e) {
				result = HttpProcessUtil.processException(e);
				return result;
			}

			HcpmsWarningDTO dto = (HcpmsWarningDTO) result.get("warnInfo");// 获取整个预警表字段
			if (!StringUtils.hasText(warnNo)) {
				warnNo = dto.getWarnNo();// 获取预警表中的预警任务编号
			}
			// staffList:获取的是医务人员列表
			result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONArray("staffList"), user.getUsername(),
					warnNo, WarnConstants.TARGET_TYPE_STAFF);// 保存医务人员数据,返回保存成功或保存失败
			// insurList:获取的是参保人员列表
			result = hcpmsWarnService.editHcpmsWarnTarget(transferJson.getJSONArray("insurList"), user.getUsername(),
					warnNo, WarnConstants.TARGET_TYPE_INSURANCE);// 保存参保人员数据,返回保存成功或保存失败
			// 启动
			HcpmsWorkFlowVO wfvo = new HcpmsWorkFlowVO();
			List<Authority> authorityList = user.getAuthorities();// 获取角色实体类集合
			List<String> role = new ArrayList<String>();
			for (Authority authority : authorityList) {
				role.add(authority.getAuthority());// 获取角色名集合
			}
			wfvo.setRole(role);
			wfvo.setTaskNo(warnNo);
			Map<String, String> condition = new HashMap<String, String>();
			condition.put("AUDIT_OPINION", dto.getApproveOpinion());// 将审批意见存放到集合中
			wfvo.setParamValue(condition);
			if (WarnConstants.WARN_PROCESS_BACK.equals(dto.getApproveOpinion())) {// 如果审批意见是流程跳转不同意时
				wfvo.setActCurrent(beforePerson);// 设置当前处理人Id
			}
			String actCurrent = warningWorkFlowService.processWorkFlow(wfvo);// 获取流转流程的当前节点

			// 更新状态
			HcpmsWarningDTO warnDto = new HcpmsWarningDTO();
			warnDto.setWarnNo(warnNo);
			warnDto.setUpdatedBy(user.getUsername());
			warnDto.setStatus(actCurrent);
			hcpmsWarnService.updateHcpmsWarn(warnDto);// 修改预警表
			if ("N2014009".equals(actCurrent)) {// 如果当前节点为N2014009(已结案)
				// 流程结束 扣分信息转移
				Map<String, Object> paramMap = new HashMap<String, Object>();
				paramMap.put("warnNo", warnNo);
				paramMap.put("userName", user.getUsername());
				integrityMedicalService.addIntegrityPointTemps(paramMap);
			}
			hcpmsWarnService.deleteStorageDateAll(warnNo, null);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		// ===========================================================================================
		result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
		result.put(WarnConstants.MSG_KEY, WarnConstants.SAVE_SUCCESS);
		return result;
	}

	// -------------------------------------------------------------------------
	/**
	 * 预警的批量审批
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "warnApproveWarnsps.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> warnApproveWarnsps(HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		int notPowerError = 0;// 处理的节点已经变更
		int outPowerError = 0;// 同组其他人员已经对其进行操作
		int systemError = 0;// 系统数据库错误
		int size = 0;
		// 获取参数
		try {
			UserDetails user = (UserDetails) request.getSession().getAttribute("user");
			String str = HttpProcessUtil.readRequestBody(request);
			JSONObject transferJson = JSON.parseObject(str);
			String deptCode = transferJson.getString("deptCode");// 审核意见(01:同意02:不同意)
			String warnfeeTypeCode = transferJson.getString("warnfeeTypeCode");// 意见说明
			if (null == warnfeeTypeCode) {
				warnfeeTypeCode = "";
			}
			if (StringUtils.hasText(deptCode)) {
				JSONArray jsonArr = transferJson.getJSONArray("approveList");
				size = jsonArr.size();// :批量条数
				if (null != jsonArr && jsonArr.size() > 0) {
					for (int i = 0; i < jsonArr.size(); i++) {

						JSONObject tempJson = jsonArr.getJSONObject(i);
						HcpmsWarningDTO dto = JSONObject.toJavaObject(tempJson, HcpmsWarningDTO.class);
						String warnNo = dto.getWarnNo();
						String status = WarnConstants.WARN_STATUS_8;
						String processState = warningWorkFlowService.vilidateOrBindUser(warnNo, user.getUsername(),
								status);// 获取操作权限级别(0:有操作权限;1没有操作权限
										// 2：操作节点已变更)
						if (WarnConstants.PROCESS_NOT_POWER.endsWith(processState)) {// 如果流程节点已变更
							notPowerError += 1;
							continue;
						} else if (WarnConstants.PROCESS_OUT_POWER.endsWith(processState)) {// 如果没有操作权限
							outPowerError += 1;
							continue;
						}

						if (WarnConstants.FAILED_VALIDATE_STATE_VALUE.equals(result.get(WarnConstants.STATE_KEY))) {

						} else {
							// 根据预警编号去暂存表中查找该条预警信息是否已经暂存
							HcpmsStorageDTO hsdto = new HcpmsStorageDTO();// 暂存实体类
							hsdto.setBusinessId(dto.getWarnNo());
							hsdto.setModuleType(WarnConstants.WARN_MODULE_TYPE);// 设置模块
							hsdto.setUserId(user.getUsername());
							List<HcpmsStorageDTO> hsdList = hcpmsStorageService.getStorageDataList(hsdto);

							getStorageData(hsdList, result, dto, user);// 如果数据在暂存中，获取暂存中的数据

							Map<String, Object> paMap = new HashMap<String, Object>();
							paMap.put("caseType", "01");// 01:预警，02：稽核
							paMap.put("caseNo", dto.getWarnNo());// 案件号
							paMap.put("userName", user.getUsername());// 当前操作人
							integrityMedicalService.batchAddPointCutTemps(paMap);
							// =================================================================================
							// hsdList.size()=0 数据不在暂存中(审核意见在或不在暂存中)
							HcpmsWarnsDTO hd = hcpmsWarnService.getWarnInfo(dto.getWarnNo());
							hd.setApproveOpinion(deptCode);// 设置审批意见
							hd.setApproveDesc(warnfeeTypeCode);// 设置意见说明
							hd.setWarnNo(dto.getWarnNo());
							try {
								result = hcpmsWarnService.editHcpmsWarn((JSONObject) JSONObject.toJSON(hd),
										user.getUsername(), dto.getWarnNo());// 根据预警实体类等信息修改预警表(为预警表设置审批意见和意见说明等)
							} catch (Exception e) {
								systemError += 1;
								result = HttpProcessUtil.processException(e);
								// return result;
							}
							HcpmsWarningDTO waring = (HcpmsWarningDTO) result.get("warnInfo");
							getTypePlsp(user, waring, transferJson);// 流转流程

						}
						hcpmsWarnService.deleteStorageDateAll(warnNo, null);
						// ===========================================================================================
					}
				}// end 'null != jsonArr'
			}// end if
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
		result.put(WarnConstants.WARN_BATCH_COUNT_SUCCESS, size - notPowerError - outPowerError - systemError);
		result.put(WarnConstants.WARN_BATCH_COUNT_FAILED, notPowerError + outPowerError + systemError);
		batchMessageProcess(result);
		return result;
	}

	public void getStorageData(List<HcpmsStorageDTO> hsdList, Map<String, Object> result, HcpmsWarningDTO dto,
			UserDetails user) {
		if (hsdList.size() > 0) {
			// 该条数据某一部分或几份在暂存
			for (HcpmsStorageDTO hs : hsdList) {
				String type = hs.getBusinessType();
				if (type.equals(WarnConstants.WARN_BUSINESS_STAFF)) {// 医护人员在暂存中存在
					result = hcpmsWarnService.editHcpmsWarnTarget((JSONArray) JSONObject.toJSON(hs.getDataMap()),
							user.getUsername(), dto.getWarnNo(), WarnConstants.TARGET_TYPE_STAFF);// result:获得的是保存成功或保存失败
				} else if (type.equals(WarnConstants.WARN_BUSINESS_INSUR)) {// 参保人员在暂存中
					result = hcpmsWarnService.editHcpmsWarnTarget((JSONArray) JSONObject.toJSON(hs.getDataMap()),
							user.getUsername(), dto.getWarnNo(), WarnConstants.TARGET_TYPE_INSURANCE);// result:获得的是保存成功或保存失败
				} else if (type.equals(WarnConstants.WARN_BUSINESS_WARN)) {// 主对象在暂存中
					result = hcpmsWarnService.editHcpmsWarn((JSONObject) JSONObject.toJSON(hs.getDataMap()),
							user.getUsername(), dto.getWarnNo());// 根据预警实体类等信息修改预警表(为预警表设置审核人和审核时间)
				}
			}
		}

	}

	public void getTypePlsp(UserDetails user, HcpmsWarningDTO dto, JSONObject transferJson) throws Exception {
		// 启动
		HcpmsWorkFlowVO wfvo = new HcpmsWorkFlowVO();
		List<Authority> authorityList = user.getAuthorities();// 获取角色实体类集合
		List<String> role = new ArrayList<String>();
		for (Authority authority : authorityList) {
			role.add(authority.getAuthority());// 获取角色名集合
		}
		wfvo.setRole(role);
		// wfvo.setAssigner(user.getUsername());
		wfvo.setTaskNo(dto.getWarnNo());
		Map<String, String> condition = new HashMap<String, String>();
		condition.put("AUDIT_OPINION", dto.getApproveOpinion());// 将审批意见存放到集合中
		wfvo.setParamValue(condition);
		if (WarnConstants.WARN_PROCESS_BACK.equals(dto.getApproveOpinion())) {// 如果审批意见是流程跳转不同意时
			// transferJson.getString("beforePerson"):
			// 获取审批前的审核人：warnsh
			wfvo.setActCurrent(transferJson.getString("beforePerson"));// 设置当前处理人Id
		}
		String actCurrent = warningWorkFlowService.processWorkFlow(wfvo);// 获取流转流程的当前节点

		// 更新状态
		HcpmsWarningDTO warnDto = new HcpmsWarningDTO();
		warnDto.setWarnNo(dto.getWarnNo());
		warnDto.setUpdatedBy(user.getUsername());
		warnDto.setStatus(actCurrent);
		hcpmsWarnService.updateHcpmsWarn(warnDto);// 修改预警表
		if ("N2014009".equals(actCurrent)) {// 如果当前节点为N2014009(已结案)
			// 流程结束 扣分信息转移
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("warnNo", dto.getWarnNo());
			paramMap.put("userName", user.getUsername());
			integrityMedicalService.addIntegrityPointTemps(paramMap);
		}
	}

	// -------------------------------------------------------------------------

	/**
	 * 查询预警事件的信息（包括医疗机构，医护人员，参保人，网上筛查）
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("queryWarnData.do")
	@ResponseBody
	public Map<String, Object> getWarnData(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String warnNo = request.getParameter("warnNo");
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		if (!"".equals(warnNo) && warnNo != null) {
			map.put("warnNo", warnNo);
		}
		map.put("userId", user.getUsername());
		Map<String, Object> result = hcpmsWarnService.queryWarnData(map);
		return result;
	}

	/***
	 * 根据CODE_TYPE的类型集合查询数据字典数据
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("getCodeList.do")
	@ResponseBody
	public Map<String, Object> getCodeList(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String[] codeType = request.getParameterValues("codeType");
		map.put("codeTypes", codeType);
		Map<String, Object> result = hcpmsWarnService.getCodeList(map);
		return result;
	}

	/**
	 * 查询医院反馈信息
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("getFeedBackList.do")
	@ResponseBody
	public Map<String, Object> getFeedBackList(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String warnNo = request.getParameter("warnNo");
		map.put("warnno", warnNo);
		Map<String, Object> result = hcpmsWarnService.getFeedBackList(map);
		return result;
	}

	/**
	 * 查询结果评估信息
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("getWarnResult.do")
	@ResponseBody
	public Map<String, Object> getWarnResult(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		String warnNo = request.getParameter("warnNo");
		map.put("warnNo", warnNo);
		map.put("userId", user.getUsername());
		Map<String, Object> result = hcpmsWarnService.getWarnResult(map);
		return result;
	}

	/**
	 * 查询结果复审信息
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("getAuditResult.do")
	@ResponseBody
	public Map<String, Object> getAuditResult(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		String warnNo = request.getParameter("warnNo");
		map.put("warnNo", warnNo);
		map.put("userId", user.getUsername());
		Map<String, Object> result = hcpmsWarnService.getAuditResult(map);
		return result;
	}

	/**
	 * 查询结果复审信息
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("getWarnNotice.do")
	@ResponseBody
	public Map<String, Object> getWarnNotice(HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		String warnNo = request.getParameter("warnNo");
		Map<String, Object> resultNotice = hcpmsWarnService.getWarnNotice(warnNo, WarnConstants.TASK_TYPE_WARNING,
				WarnConstants.DOC_TYPE_TOLD, user.getUsername());
		result.put("resultNotice", resultNotice);
		return result;
	}

	/**
	 * 新增预警事件查询医疗机构
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("getMedicalList.do")
	@ResponseBody
	public Map<String, Object> getMedicalList(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String orgCode = request.getParameter("orgCode");
		String orgName = request.getParameter("orgName");
		String orgType = request.getParameter("orgType");
		String orgLevel = request.getParameter("orgLevel");
		String limit = request.getParameter("limit");
		String page = request.getParameter("page");
		if (StringUtils.hasText(orgCode)) {
			map.put("orgCode", orgCode);
		}
		if (StringUtils.hasText(orgName)) {
			map.put("orgName", orgName);
		}
		if (StringUtils.hasText(orgType)) {
			map.put("orgType", orgType);
		}
		if (StringUtils.hasText(orgLevel)) {
			map.put("orgLevel", orgLevel);
		}
		if (StringUtils.hasText(limit)) {
			map.put("limit", limit);
		}
		if (StringUtils.hasText(page)) {
			map.put("page", page);
		}
		Map<String, Object> result = hcpmsWarnService.getMedicalList(map);
		return result;
	}

	/**
	 * 新增预警事件查询医护人员
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("getStaffList.do")
	@ResponseBody
	public Map<String, Object> getStaffList(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String orgCode = request.getParameter("orgCode");
		String name = request.getParameter("name");
		String personNo = request.getParameter("personNo");
		String cardNo = request.getParameter("cardNo");
		if (StringUtils.hasText(orgCode)) {
			map.put("orgCode", orgCode);
		}
		if (StringUtils.hasText(name)) {
			map.put("name", name);
		}
		if (StringUtils.hasText(personNo)) {
			map.put("personNo", personNo);
		}
		if (StringUtils.hasText(cardNo)) {
			map.put("cardNo", cardNo);
		}
		Map<String, Object> result = hcpmsWarnService.getStaffList(map);
		return result;
	}

	/**
	 * 新增预警事件参保人员
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("getInsuranceList.do")
	@ResponseBody
	public Map<String, Object> getInsuranceList(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String name = request.getParameter("name");
		String cardNo = request.getParameter("cardNo");
		String pcNo = request.getParameter("pcNo");
		String personNo = request.getParameter("personNo");
		String personType = request.getParameter("personType");
		String limit = request.getParameter("limit");
		String page = request.getParameter("page");
		if (StringUtils.hasText(name)) {
			map.put("name", name);
		}
		if (StringUtils.hasText(cardNo)) {
			map.put("cardNo", cardNo);
		}
		if (StringUtils.hasText(pcNo)) {
			map.put("pcNo", pcNo);
		}
		if (StringUtils.hasText(personNo)) {
			map.put("personNo", personNo);
		}
		if (StringUtils.hasText(personType)) {
			map.put("personType", personType);
		}
		if (StringUtils.hasText(limit)) {
			map.put("limit", limit);
		}
		if (StringUtils.hasText(page)) {
			map.put("page", page);
		}
		Map<String, Object> result = hcpmsWarnService.getInsuranceList(map);
		return result;
	}

	/**
	 * 获取和设置基础数据
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("getBaseFormParam.do")
	@ResponseBody
	public Map<String, Object> getBaseFormParam(HttpServletRequest request) {
		// UserDetails user = (UserDetails)
		// request.getSession().getAttribute("user");
		String[] codeType = request.getParameterValues("codeType");
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < codeType.length; i++) {
			list.add(codeType[i]);
		}
		list.add(WarnConstants.TYPE_REGION_NAME);
		list.add(WarnConstants.TYPE_WARN_INSCRIBE);
		Map<String, Object> result = hcpmsWarnService.getBaseFormParam(list);
		setMapDateValue(5, result);

		return result;
	}

	public void setMapDateValue(int feelbackNum, Map<String, Object> map) {
		SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		try {
			String today = sft.format(date);
			SimpleDateFormat sftMonth = new SimpleDateFormat("yyyy-MM");
			String monthFirst = sftMonth.format(date) + "-01";
			Calendar cal = Calendar.getInstance();
			cal.setTime(sft.parse(monthFirst));
			cal.add(Calendar.MONTH, 1);
			date = new Date(cal.getTime().getTime() - 60 * 60 * 100 * 24);
			String monthLast = sft.format(date);
			date = new Date(sft.parse(today).getTime() + 60 * 60 * 100 * 24 * feelbackNum);
			String feedbackDate = sft.format(date);
			map.put("today", today);
			map.put("monthFirst", monthFirst);
			map.put("monthLast", monthLast);
			map.put("feedbackDate", feedbackDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 预警通知单号
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "createWarnNoticeNum.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> createWarnNoticeNum(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		StringBuilder bd = new StringBuilder();
		// 获取当前年份
		String year = new SimpleDateFormat("yyyy").format(new Date());
		// 获取处理方式参数（Y为书面预警，K为约谈预警）
		String handMethod = request.getParameter("handMethod");
		// 获取预警业务参数（M表示门诊、Z表示住院、D表示药店）
		String warnBusiness = request.getParameter("warnBusiness");
		handMethod = handMethod == null ? "" : handMethod;
		warnBusiness = warnBusiness == null ? "" : warnBusiness;
		// 默认的批次号
		String batchNo = "01";
		// 默认月份
		String month = "00";
		// 生成的序列号
		String num = hcpmsWarnService.createWarnNoticeNum(map);
		if (num.length() == 1) {
			num = "00" + num;
		} else if (num.length() == 2) {
			num = "0" + num;
		}
		// 组合成预警通知单号
		String strbd = bd.append(handMethod).append(warnBusiness).append(year).append(batchNo).append(month)
				.append(num).toString();
		map.put("noticeNum", strbd);
		return map;
	}

	/***
	 * 撤回预警事件
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("backWarnProcess.do")
	@ResponseBody
	public Map<String, Object> backWarnProcess(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		// 获取参数
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		String warnNo = request.getParameter("warnNo");
		String status = request.getParameter("status");
		// 启动
		try {
			Map<String, String> condition = new HashMap<String, String>();
			if (WarnConstants.WARN_STATUS_4.equals(status) || WarnConstants.WARN_STATUS_7.equals(status)
					|| WarnConstants.WARN_STATUS_8.equals(status)) {
				condition.put("AUDIT_OPINION", WarnConstants.WARN_PROCESS_BACK);
			}
			// 判断节点是否已经发生变化
			String actCurrent = warningWorkFlowService.startWorkFlow(warnNo, user, condition);
			if (!actCurrent.equals(status)) {
				result.put(WarnConstants.STATE_KEY, WarnConstants.FAILED_STATE_VALUE);
				result.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_NOT_POWER_ERROR
						+ WarnConstants.WARN_PROCESS_REST_FAILED);
				return result;
			}
			// 流程
			HcpmsWorkFlowVO wfvo = new HcpmsWorkFlowVO();
			wfvo.setTaskNo(warnNo);
			wfvo.setActCurrent(user.getUsername());
			wfvo.setParamValue(condition);
			actCurrent = warningWorkFlowService.processWorkFlow(wfvo);
			// 更新状态
			HcpmsWarningDTO warnDto = new HcpmsWarningDTO();
			warnDto.setWarnNo(warnNo);
			warnDto.setUpdatedBy(user.getUsername());
			warnDto.setStatus(actCurrent);
			hcpmsWarnService.updateHcpmsWarn(warnDto);
			hcpmsWarnService.deleteStorageDateAll(warnNo, null);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
		result.put(WarnConstants.MSG_KEY, WarnConstants.WARN_PROCESS_REST_SUCCESS);
		return result;
	}

	/**
	 * 验证通知单信息
	 * 
	 * @param map
	 * @param warnNoBiz
	 * @return
	 */
	public String checkField(Map<String, Object> map, String warnNoBiz) {

		if (map == null || map.size() <= 0) {
			return warnNoBiz + " 处理方式为书面和约谈时，通知单里的内容不能为空！";
		}
		if (map.get("content") == null || "".equals(map.get("content"))) {
			return warnNoBiz + " 的通知单预警内容不能为空！";
		}
		if (map.get("datestart") == null || "".equals(map.get("datestart"))) {
			return warnNoBiz + " 的通知单预警时段开始时段不能为空！";
		}
		if (map.get("dateend") == null || "".equals(map.get("dateend"))) {
			return warnNoBiz + " 的通知单预警时段结束时段不能为空！";
		}
		if (map.get("requirement") == null || "".equals(map.get("requirement"))) {
			return warnNoBiz + " 的通知单预警要求不能为空！";
		}
		if (map.get("noticeDate") == null || "".equals("noticeDate")) {
			return warnNoBiz + " 的通知单日期不能为空";
		}
		return null;
	}

	/**
	 * 预警筛查之批量处理
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "batchAnalysisProcess.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> batchAnalysisProcess(HttpServletRequest request) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		// 获取参数
		String str = HttpProcessUtil.readRequestBody(request);
		JSONObject transferJson = JSON.parseObject(str);
		String chooseRow = transferJson.getString("chooseRow");
		JSONArray array = JSONObject.parseArray(chooseRow);
		// 定义一个计数器
		int count = 0;
		StringBuffer buff = new StringBuffer();
		for (int i = 0; i < array.size(); i++) {
			JSONObject obj = array.getJSONObject(i);
			String warnNo = (String) obj.get("warnNo");
			String warnNoBiz = (String) obj.get("warnNoBiz");
			String status = (String) obj.get("actNo");
			// 权限验证
			if (!"".equals(warnNo) && warnNo != null && !"".equals(status) && status != null) {
				String processState = warningWorkFlowService.vilidateOrBindUser(warnNo, user.getUsername(), status);// 获取操作权限级别(0:有操作权限;1没有操作权限
																													// 2：操作节点已变更)
				if (WarnConstants.PROCESS_NOT_POWER.endsWith(processState)) {// 如果操作权限级别是：流程节点已变更
					map.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);// 返回成功的状态
					map.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_NOT_POWER_ERROR);// 提示处理节点已变更
					map.put("resultMsg", "您的选项中有节点已变更，请重新选择！");
					return map;
				} else if (WarnConstants.PROCESS_OUT_POWER.endsWith(processState)) {// 如果操作权限级别是：没有操作权限
					map.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
					map.put(WarnConstants.MSG_KEY, WarnConstants.PROCESS_OUT_POWER_ERROR);// 提示同组其他人员已经对其进行操作!
					map.put("resultMsg", "您的选项中有同组其他人员已经对其进行操作，请重新选择！");
					return map;
				}
			}

			if (!"".equals(warnNo) && warnNo != null) {
				map.put("warnNo", warnNo);
				map.put("userId", user.getUsername());
				// 根据预警编号获取预警信息
				HcpmsWarnsDTO dto = hcpmsWarnService.getWarnInfo(warnNo);
				// 验证预警信息
				String message = vilidateWarnInfo(dto, warnNo, warnNoBiz, user.getUsername());
				if ("".equals(message) || message == null) {
					try {
						Map<String, String> condition = new HashMap<String, String>();
						condition.put("SOURCE", dto.getSource());
						String actCurrent = warningWorkFlowService.startWorkFlow(warnNo, user, condition);
						// 提交
						HcpmsWorkFlowVO wfvo = new HcpmsWorkFlowVO();
						wfvo.setTaskNo(warnNo);
						wfvo.setActCurrent(user.getUsername());
						actCurrent = warningWorkFlowService.processWorkFlow(wfvo);
						// 更新状态
						HcpmsWarningDTO warnDto = new HcpmsWarningDTO();
						warnDto.setWarnNo(warnNo);
						warnDto.setUpdatedBy(user.getUsername());
						warnDto.setStatus(actCurrent);
						hcpmsWarnService.updateHcpmsWarn(warnDto);
						count++;
						hcpmsWarnService.deleteStorageDateAll(warnNo, null);
					} catch (Exception e) {
						e.printStackTrace();
					}
				} else {
					buff.append(message);
				}
			}

		}
		map.put("resultMsg", "您选择的批量操作有：" + array.size() + "条，其中有" + count + "条成功，" + (array.size() - count) + "条失败。");
		// map.put("resultMsg", "您的批量操作有：" + count + "条成功，" + (array.size() -
		// count) + "条失败。" + buff);
		return map;
	}

	/**
	 * 验证主信息
	 * 
	 * @param dto
	 * @param warnNo
	 * @param warnNoBiz
	 * @param userId
	 * @return
	 */
	private String vilidateWarnInfo(HcpmsWarnsDTO dto, String warnNo, String warnNoBiz, String userId) {
		if (dto == null) {
			return warnNoBiz + " 的预警事件没有生成！";
		}
		if ("".equals(dto.getWarnDate()) || dto.getWarnDate() == null) {
			return warnNoBiz + " 的预警事件受理日期不能为空！";
		}
		if ("".equals(dto.getSource()) || dto.getSource() == null) {
			return warnNoBiz + " 的预警来源不能为空！";
		}
		if ("".equals(dto.getSourceType()) || dto.getSourceType() == null) {
			return warnNoBiz + " 的来源方式不能为空！";
		}
		if ("".equals(dto.getSourceObject()) || dto.getSourceType() == null) {
			return warnNoBiz + " 的来源对象不能为空！";
		}
		if ("".equals(dto.getSummary()) || dto.getSummary() == null) {
			return warnNoBiz + " 的预警原因不能为空！";
		}
		if ("".equals(dto.getReason()) || dto.getReason() == null) {
			return warnNoBiz + " 的预警内容不能为空！";
		}
		if ("".equals(dto.getStartDate()) || dto.getStartDate() == null) {
			return warnNoBiz + " 的预警时段开始时间不能为空！";
		}
		if ("".equals(dto.getEndDate()) || dto.getEndDate() == null) {
			return warnNoBiz + " 的预警时段结束时间不能为空！";
		}
		if ("".equals(dto.getProcess()) || dto.getProcess() == null) {
			return warnNoBiz + " 的处理方式不能为空！";
		} else if (WarnConstants.WARN_PROCESS_TYPE_02.equals(dto.getProcess())
				|| WarnConstants.WARN_PROCESS_TYPE_04.equals(dto.getProcess())) {
			// 获取自查通知单信息
			Map<String, Object> map = hcpmsWarnService.getWarnNotice(warnNo, WarnConstants.TASK_TYPE_WARNING,
					WarnConstants.DOC_TYPE_NOTICE, userId);
			return checkField(map, warnNoBiz);

		}
		return null;
	}

	/**
	 * 核对结果告知书的存在问题和处理决定
	 */
	public boolean checkResultAuditNotice(Map<String, Object> storageMap) {
		boolean result = false;
		if (storageMap.containsKey(WarnConstants.WARN_BUSINESS_RESULT_TOLD)) {// 存在暂存的结果告知书
			JSONObject checkResult = (JSONObject) storageMap.get(WarnConstants.WARN_BUSINESS_RESULT_TOLD);
			String problem = checkResult.getString("problem");
			String decide = checkResult.getString("decide");
			if (null != problem && !problem.equals("") && null != decide && !decide.equals("")) {
				result = true;
			}
		}
		return result;
	}

	/**
	 * 获取暂存数据
	 * 
	 * @param storageList
	 * @return
	 */
	public Map<String, Object> getAuditStorage(HcpmsStorageDTO vo) {
		Map<String, Object> result = new HashMap<String, Object>();
		List<HcpmsStorageDTO> storageList = storageService.getStorageDataList(vo);
		for (HcpmsStorageDTO dto : storageList) {
			if (dto.getBusinessType().equals(WarnConstants.WARN_BUSINESS_STAFF)) {// 医护人员
				result.put(WarnConstants.WARN_BUSINESS_STAFF, dto.getDataMap());
			}
			if (dto.getBusinessType().equals(WarnConstants.WARN_BUSINESS_SCREEN)) {// 网上筛查
				result.put(WarnConstants.WARN_BUSINESS_SCREEN, dto.getDataMap());
			}
			if (dto.getBusinessType().equals(WarnConstants.WARN_BUSINESS_WARN)) {// 主对象(包括初审和审批)
				result.put(WarnConstants.WARN_BUSINESS_WARN, dto.getDataMap());
			}
			if (dto.getBusinessType().equals(WarnConstants.WARN_BUSINESS_POINT)) {// 扣分的业务类型
				result.put(WarnConstants.WARN_BUSINESS_POINT, dto.getDataMap());
			}
			if (dto.getBusinessType().equals(WarnConstants.WARN_BUSINESS_INSUR)) {// 参保人
				result.put(WarnConstants.WARN_BUSINESS_INSUR, dto.getDataMap());
			}
			if (dto.getBusinessType().equals(WarnConstants.WARN_BUSINESS_ASSESS_LIST)) {// 结论评估左
				result.put(WarnConstants.WARN_BUSINESS_ASSESS_LIST, dto.getDataMap());
			}
			if (dto.getBusinessType().equals(WarnConstants.WARN_BUSINESS_ASSESS)) {// 结论评估右
				result.put(WarnConstants.WARN_BUSINESS_ASSESS, dto.getDataMap());
			}
			if (dto.getBusinessType().equals(WarnConstants.WARN_BUSINESS_RESULT_TOLD)) {// 结果告知书
				result.put(WarnConstants.WARN_BUSINESS_RESULT_TOLD, dto.getDataMap());
			}
		}
		return result;
	}

	/**
	 * 核对医院反馈金额和反馈评估金额是否相同 添加结果告知书的验证
	 */
	public boolean checkFeedBackAmount(List<WarningCheckDetailDTO> feedBackDataList, Map<String, Object> storageMap) {
		boolean result = false;
		if (storageMap.containsKey(WarnConstants.WARN_BUSINESS_RESULT_TOLD)) {// 存在暂存的结果告知书
			JSONObject checkResult = (JSONObject) storageMap.get(WarnConstants.WARN_BUSINESS_RESULT_TOLD);
			String problem = checkResult.getString("problem");
			String decide = checkResult.getString("decide");
			if (null == problem || problem.equals("") || null == decide || decide.equals("")) {
				return result;
			}
		}
		if (storageMap.containsKey(WarnConstants.WARN_BUSINESS_ASSESS_LIST)) {// 存在暂存的结果评估数据
			JSONArray assessArray = (JSONArray) storageMap.get(WarnConstants.WARN_BUSINESS_ASSESS_LIST);
			double feedBackAmount = 0;
			double assessAmount = 0;
			for (WarningCheckDetailDTO dto : feedBackDataList) {
				feedBackAmount += Double.parseDouble(dto.getFeeAmount());
			}
			for (int i = 0; i < assessArray.size(); i++) {
				assessAmount += ((JSONObject) assessArray.get(i)).getDoubleValue("amount");
			}
			// result = feedBackAmount == assessAmount;
			result = (assessAmount >= feedBackAmount);
		}
		return result;
	}

	/**
	 * 计算结果评估的合计金额和综合扣分
	 * 
	 * @return
	 */
	public Map<String, Object> getAssessResultFeeAndPoint(Map<String, Object> storageMap) {
		Map<String, Object> result = new HashMap<String, Object>();
		double assessPoint = 0;
		double assessAmount = 0;
		if (storageMap.containsKey(WarnConstants.WARN_BUSINESS_ASSESS_LIST)) {// 存在暂存的结果评估数据
			JSONArray assessArray = (JSONArray) storageMap.get(WarnConstants.WARN_BUSINESS_ASSESS_LIST);
			for (int i = 0; i < assessArray.size(); i++) {
				assessAmount += ((JSONObject) assessArray.get(i)).getDoubleValue("amount");
				assessPoint += ((JSONObject) assessArray.get(i)).getDoubleValue("itemCutpoint");
			}
		}
		result.put("sumAmount", assessAmount);
		result.put("point", assessPoint);
		return result;
	}

	/**
	 * 核对预警登记的不为空字段
	 */
	public boolean checkWarnFieldValid(Map<String, Object> warnInfoMap) {
		final boolean result = false;
		HcpmsWarnsDTO warnInfo = (HcpmsWarnsDTO) warnInfoMap.get("warnInfo");
		String process = warnInfo.getProcess();
		// 书面和约谈验证自查通知书
		if (process.equals(WarnConstants.WARN_PROCESS_TYPE_02) || process.equals(WarnConstants.WARN_PROCESS_TYPE_04)) {
			if (!warnInfoMap.containsKey("notice")) {
				return result;
			} else {
				Map<String, Object> noticeMap = (Map<String, Object>) warnInfoMap.get("notice");
				if (!noticeMap.containsKey("content")) {
					return result;
				}
			}
		}
		if (null == warnInfo.getWarnDate() || warnInfo.getWarnDate().equals("")) {// 受理日期
			return result;
		}
		if (null == warnInfo.getSource() || warnInfo.getSource().equals("")) {// 案件来源
			return result;
		}
		if (null == warnInfo.getSourceType() || warnInfo.getSourceType().equals("")) {// 来源方式
			return result;
		}
		if (null == warnInfo.getSourceObject() || warnInfo.getSourceObject().equals("")) {// 来源对象
			return result;
		}
		if (null == warnInfo.getSummary() || warnInfo.getSummary().equals("")) {// 预警原因
			return result;
		}
		if (null == warnInfo.getStartDate() || warnInfo.getStartDate().equals("")) {// 预警时段开始
			return result;
		}
		if (null == warnInfo.getEndDate() || warnInfo.getEndDate().equals("")) {// 预警时段结束
			return result;
		}
		if (null == warnInfo.getReason() || warnInfo.getReason().equals("")) {// 预警内容
			return result;
		}
		if (!warnInfoMap.containsKey("warnMedicalInfo")) {// 医疗机构
			return result;
		}
		return !result;
	}

	/**
	 * 批量提交预警事件
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "submitWarnBatchProcess.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> submitWarnBatchProcess(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		String str = HttpProcessUtil.readRequestBody(request);
		JSONObject transferJson = JSON.parseObject(str);
		JSONArray submitBatchArray = transferJson.getJSONArray("batchWarnList");// 选择的批量预警事件
		StringBuffer checkStr = new StringBuffer();
		Map<String, Object> bufferStorageMap = new HashMap<String, Object>();
		int batchSize = submitBatchArray.size();
		int checkError = 0;// 验证不通过
		int notPowerError = 0;// 处理的节点已经变更
		int outPowerError = 0;// 同组其他人员已经对其进行操作
		int systemError = 0;// 系统数据库错误
		for (int i = 0; i < batchSize; i++) {
			WarningGtasksDTO dto = JSONObject.toJavaObject(submitBatchArray.getJSONObject(i), WarningGtasksDTO.class);// 选中的每一条
			String warnNo = dto.getWarnNo();
			String status = dto.getActNo();
			// --------查询预警事件开始
			Map<String, Object> warnInfoParamMap = new HashMap<String, Object>();
			warnInfoParamMap.put("warnNo", warnNo);
			warnInfoParamMap.put("userId", user.getUsername());
			Map<String, Object> warnInfoMap = hcpmsWarnService.queryWarnData(warnInfoParamMap);
			// --------查询预警事件结束
			if (!checkWarnFieldValid(warnInfoMap)) {// 验证不通过
				checkError += 1;
				continue;
			} else {
				if (!"".equals(warnNo) && warnNo != null && !"".equals(status) && status != null) {
					String processState = warningWorkFlowService.vilidateOrBindUser(warnNo, user.getUsername(), status);
					if (WarnConstants.PROCESS_NOT_POWER.endsWith(processState)) {
						notPowerError += 1;
						continue;
					} else if (WarnConstants.PROCESS_OUT_POWER.endsWith(processState)) {
						outPowerError += 1;
						continue;
					}
				}
				Map<String, Object> editWarnMap = new HashMap<String, Object>();
				try {
					editWarnMap = hcpmsWarnService.editHcpmsWarn((JSONObject) JSON.toJSON(warnInfoMap.get("warnInfo")),
							user.getUsername(), warnNo);
				} catch (Exception e) {
					systemError += 1;
					HttpProcessUtil.processException(e);
				}
				HcpmsWarningDTO warning = (HcpmsWarningDTO) editWarnMap.get("warnInfo");
				if ("".equals(warnNo) || warnNo == null) {
					warnNo = warning.getWarnNo();
				}
				// 启动
				try {
					Map<String, String> condition = new HashMap<String, String>();
					condition.put("SOURCE", warning.getSource());
					String actCurrent = warningWorkFlowService.startWorkFlow(warnNo, user, condition);
					// 提交
					HcpmsWorkFlowVO wfvo = new HcpmsWorkFlowVO();
					wfvo.setTaskNo(warnNo);
					wfvo.setActCurrent(user.getUsername());
					actCurrent = warningWorkFlowService.processWorkFlow(wfvo);
					// 更新状态
					HcpmsWarningDTO warnDto = new HcpmsWarningDTO();
					warnDto.setWarnNo(warnNo);
					warnDto.setUpdatedBy(user.getUsername());
					warnDto.setStatus(actCurrent);
					hcpmsWarnService.updateHcpmsWarn(warnDto);
				} catch (Exception e) {
					systemError += 1;
					HttpProcessUtil.processException(e);
				}
				// }

			}
		}

		result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
		result.put(WarnConstants.WARN_BATCH_COUNT_SUCCESS, batchSize - notPowerError - outPowerError - systemError
				- checkError);
		result.put(WarnConstants.WARN_BATCH_COUNT_FAILED, notPowerError + outPowerError + systemError + checkError);

		batchMessageProcess(result);
		return result;
	}

	void batchMessageProcess(Map<String, Object> result) {
		String stateKey = result.get(WarnConstants.STATE_KEY).toString();
		if (stateKey.equals("0")) {
			result.put(WarnConstants.MSG_KEY, "操作成功,其中成功" + result.get(WarnConstants.WARN_BATCH_COUNT_SUCCESS) + "条,失败"
					+ result.get(WarnConstants.WARN_BATCH_COUNT_FAILED) + "条!");
		} else {

		}
	}

	/***
	 * 批量审核预警事件
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "auditWarnBatchProcess.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> auditWarnBatch(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		// 获取参数
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		String str = HttpProcessUtil.readRequestBody(request);
		JSONObject transferJson = JSON.parseObject(str);
		result = hcpmsWarnService.auditWarnBatch(transferJson, user.getUsername());
		return result;
	}

	/**
	 * 批量反馈评估预警事件
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "assessWarnBatchProcess.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> assessWarnBatchProcess(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		String str = HttpProcessUtil.readRequestBody(request);
		JSONObject transferJson = JSON.parseObject(str);
		JSONObject assessResult = transferJson.getJSONObject("assessResult");// 批量反馈评估信息
		JSONArray assessBatchArray = transferJson.getJSONArray("batchWarnList");// 选择的批量预警事件
		int batchSize = assessBatchArray.size();
		int checkError = 0;// 验证失败数量
		int notPowerError = 0;// 处理的节点已经变更
		int outPowerError = 0;// 同组其他人员已经对其进行操作
		for (int i = 0; i < batchSize; i++) {
			WarningGtasksDTO dto = JSONObject.toJavaObject(assessBatchArray.getJSONObject(i), WarningGtasksDTO.class);// 选中的每一条
			String warnNo = dto.getWarnNo();
			String status = dto.getActNo();
			String feedbackEndDate = dto.getFeedbackEndDate();
			// ----------医院反馈信息开始
			Map<String, Object> feedBackParamMap = new HashMap<String, Object>();
			feedBackParamMap.put("warnno", warnNo);
			Map<String, Object> feedBackDataMap = hcpmsWarnService.getFeedBackList(feedBackParamMap);
			List<WarningCheckDetailDTO> feedBackDataList = (List<WarningCheckDetailDTO>) feedBackDataMap
					.get("detailList");
			// ----------医院反馈信息结束

			// -----------暂存信息开始
			HcpmsStorageDTO vo = new HcpmsStorageDTO();
			vo.setModuleType(WarnConstants.WARN_MODULE_TYPE);
			vo.setBusinessId(dto.getWarnNo());
			vo.setUserId(user.getUsername());
			Map<String, Object> storageMap = getAuditStorage(vo);
			// ----------暂存信息结束

			if (!checkFeedBackAmount(feedBackDataList, storageMap)) {// 金额不同
				checkError += 1;
				continue;
			} else {
				// 权限验证
				if (!"".equals(warnNo) && warnNo != null && !"".equals(status) && status != null) {
					String processState = warningWorkFlowService.vilidateOrBindUser(warnNo, user.getUsername(), status);
					if (WarnConstants.PROCESS_NOT_POWER.endsWith(processState)) {
						notPowerError += 1;
						continue;

					} else if (WarnConstants.PROCESS_OUT_POWER.endsWith(processState)) {
						outPowerError += 1;
						continue;
					}
				}
				// -----------------
				// 批量记分调用方法：
				Map<String, Object> pointParamMap = new HashMap<String, Object>();
				pointParamMap.put("caseType", "01");// 01:预警，02：稽核
				pointParamMap.put("caseNo", warnNo);// 案件号
				pointParamMap.put("userName", user.getUsername());// 当前操作人
				try {
					integrityMedicalService.batchAddPointCutTemps(pointParamMap);
				} catch (BusinessException e1) {
					e1.printStackTrace();
				}
				String opinion = assessResult.getString("opinion");

				if (StringUtils.hasText(feedbackEndDate)) {

					long currentTime = new Date().getTime();

					SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

					Date feedbackDate = format.parse(feedbackEndDate);

					long feedBackLong = feedbackDate.getTime();

					if (currentTime > feedBackLong && !WarnConstants.WARN_CHECK_AUDIT_RESULT_OK.equals(opinion)) {
						opinion = WarnConstants.WARN_CHECK_AUDIT_RESULT_OK;
					}

				}
				hcpmsWarnService.editHcpmsWarnTarget((JSONArray) storageMap.get(WarnConstants.WARN_BUSINESS_STAFF),
						user.getUsername(), warnNo, WarnConstants.TARGET_TYPE_STAFF);
				hcpmsWarnService.editHcpmsWarnTarget((JSONArray) storageMap.get(WarnConstants.WARN_BUSINESS_INSUR),
						user.getUsername(), warnNo, WarnConstants.TARGET_TYPE_INSURANCE);
				hcpmsWarnService
						.editAssessResultList((JSONArray) storageMap.get(WarnConstants.WARN_BUSINESS_ASSESS_LIST),
								user.getUsername(), warnNo);
				hcpmsWarnService.editHcpmsWarnNotice(
						(JSONObject) storageMap.get(WarnConstants.WARN_BUSINESS_RESULT_TOLD), user.getUsername(),
						warnNo, WarnConstants.TASK_TYPE_WARNING, WarnConstants.DOC_TYPE_TOLD);

				assessResult.putAll(getAssessResultFeeAndPoint(storageMap));
				hcpmsWarnService.editAssessResult(assessResult, user.getUsername(), warnNo);
				// 启动
				HcpmsWorkFlowVO wfvo = new HcpmsWorkFlowVO();
				List<Authority> authorityList = user.getAuthorities();
				List<String> role = new ArrayList<String>();
				for (Authority authority : authorityList) {
					role.add(authority.getAuthority());
				}
				wfvo.setRole(role);
				// wfvo.setAssigner(user.getUsername());
				wfvo.setTaskNo(warnNo);
				Map<String, String> condition = new HashMap<String, String>();
				condition.put("SITUATION", opinion);
				wfvo.setParamValue(condition);
				String actCurrent = warningWorkFlowService.processWorkFlow(wfvo);

				// 更新状态
				HcpmsWarningDTO warnDto = new HcpmsWarningDTO();
				warnDto.setWarnNo(warnNo);
				warnDto.setUpdatedBy(user.getUsername());
				warnDto.setStatus(actCurrent);
				String isCheckBack = "0";
				if (opinion.equals("02") || opinion.equals("03")) {
					isCheckBack = "1";
				}
				if (isCheckBack != null && !isCheckBack.equals("")) {
					warnDto.setIsCheckBack(isCheckBack);
				}
				if (!WarnConstants.WARN_CHECK_AUDIT_RESULT_OK.equals(opinion)) {
					warnDto.setIsFeedback(WarnConstants.WARN_ISFEEDBACK_01);
				}
				hcpmsWarnService.updateHcpmsWarn(warnDto);
				hcpmsWarnService.deleteStorageDateAll(warnNo, null);
				// -------------------

			}
		}
		result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
		result.put(WarnConstants.WARN_BATCH_COUNT_SUCCESS, batchSize - notPowerError - outPowerError - checkError);
		result.put(WarnConstants.WARN_BATCH_COUNT_FAILED, notPowerError + outPowerError + checkError);
		batchMessageProcess(result);
		return result;
	}

	/**
	 * 批量 结论审核预警事件
	 * 
	 * @param json
	 * @param userName
	 * @return
	 */
	@RequestMapping(value = "resultAuditWarnBatchProcess.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> resultAuditWarnBatchProcess(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		String str = HttpProcessUtil.readRequestBody(request);
		JSONObject transferJson = JSON.parseObject(str);
		JSONObject resultAuditResult = transferJson.getJSONObject("resultAuditResult");// 批量结论审核信息
		JSONArray resultAuditBatchArray = transferJson.getJSONArray("batchWarnList");// 选择的批量预警事件
		int batchSize = resultAuditBatchArray.size();
		int checkError = 0;// 验证失败数量
		int notPowerError = 0;// 处理的节点已经变更
		int outPowerError = 0;// 同组其他人员已经对其进行操作
		for (int i = 0; i < batchSize; i++) {
			WarningGtasksDTO dto = JSONObject.toJavaObject(resultAuditBatchArray.getJSONObject(i),
					WarningGtasksDTO.class);// 选中的每一条
			String warnNo = dto.getWarnNo();
			String status = dto.getActNo();
			// -----------暂存信息开始
			HcpmsStorageDTO vo = new HcpmsStorageDTO();
			vo.setModuleType(WarnConstants.WARN_MODULE_TYPE);
			vo.setBusinessId(dto.getWarnNo());
			vo.setUserId(user.getUsername());
			Map<String, Object> storageMap = getAuditStorage(vo);
			// ----------暂存信息结束
			if (storageMap.containsKey(WarnConstants.WARN_BUSINESS_RESULT_TOLD)) {
				if (!checkResultAuditNotice(storageMap)) {// 验证不通过
					checkError += 1;
					continue;
				}
			}
			if (!"".equals(warnNo) && warnNo != null && !"".equals(status) && status != null) {
				String processState = warningWorkFlowService.vilidateOrBindUser(warnNo, user.getUsername(), status);
				if (WarnConstants.PROCESS_NOT_POWER.endsWith(processState)) {
					notPowerError += 1;
					continue;
				} else if (WarnConstants.PROCESS_OUT_POWER.endsWith(processState)) {
					outPowerError += 1;
					continue;
				}
			}
			// 批量记分调用方法：
			Map<String, Object> pointParamMap = new HashMap<String, Object>();
			pointParamMap.put("caseType", "01");// 01:预警，02：稽核
			pointParamMap.put("caseNo", warnNo);// 案件号
			pointParamMap.put("userName", user.getUsername());// 当前操作人
			try {
				integrityMedicalService.batchAddPointCutTemps(pointParamMap);
			} catch (BusinessException e1) {
				e1.printStackTrace();
			}
			String opinion = resultAuditResult.getString("auditResult");

			// 查询结论评估得到上一步的责任人
			Map<String, Object> assessParamMap = new HashMap<String, Object>();
			assessParamMap.put("warnNo", warnNo);
			assessParamMap.put("userId", user.getUsername());
			Map<String, Object> assessMap = hcpmsWarnService.getWarnResult(assessParamMap);
			String beforePerson = ((WarnResultDTO) assessMap.get("warnResult")).getAgent();
			if (storageMap.containsKey(WarnConstants.WARN_BUSINESS_STAFF)) {
				hcpmsWarnService.editHcpmsWarnTarget((JSONArray) storageMap.get(WarnConstants.WARN_BUSINESS_STAFF),
						user.getUsername(), warnNo, WarnConstants.TARGET_TYPE_STAFF);
			}

			if (storageMap.containsKey(WarnConstants.WARN_BUSINESS_INSUR)) {
				hcpmsWarnService.editHcpmsWarnTarget((JSONArray) storageMap.get(WarnConstants.WARN_BUSINESS_INSUR),
						user.getUsername(), warnNo, WarnConstants.TARGET_TYPE_INSURANCE);
			}

			// 保存
			hcpmsWarnService.editWarnResultAudit(resultAuditResult, user.getUsername(), warnNo);
			if (storageMap.containsKey(WarnConstants.WARN_BUSINESS_RESULT_TOLD)) {
				hcpmsWarnService.editHcpmsWarnNotice(
						(JSONObject) storageMap.get(WarnConstants.WARN_BUSINESS_RESULT_TOLD), user.getUsername(),
						warnNo, WarnConstants.TASK_TYPE_WARNING, WarnConstants.DOC_TYPE_TOLD);
			}

			// 启动
			HcpmsWorkFlowVO wfvo = new HcpmsWorkFlowVO();
			List<Authority> authorityList = user.getAuthorities();
			List<String> role = new ArrayList<String>();
			for (Authority authority : authorityList) {
				role.add(authority.getAuthority());
			}
			wfvo.setRole(role);
			// wfvo.setActCurrent(user.getUsername());
			wfvo.setTaskNo(warnNo);
			Map<String, String> condition = new HashMap<String, String>();
			condition.put("AUDIT_OPINION", opinion);

			if (!WarnConstants.WARN_PROCESS_NEXT.equals(opinion)) {
				wfvo.setActCurrent(beforePerson);
			}
			wfvo.setParamValue(condition);
			String actCurrent = warningWorkFlowService.processWorkFlow(wfvo);
			// 更新状态
			HcpmsWarningDTO warnDto = new HcpmsWarningDTO();
			warnDto.setWarnNo(warnNo);
			warnDto.setUpdatedBy(user.getUsername());
			warnDto.setStatus(actCurrent);
			String isCheckBack = transferJson.getString("isCheckBack");
			if (isCheckBack != null && !isCheckBack.equals("")) {
				warnDto.setIsCheckBack(isCheckBack);
			}
			hcpmsWarnService.updateHcpmsWarn(warnDto);
			hcpmsWarnService.deleteStorageDateAll(warnNo, null);
		}

		result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
		result.put(WarnConstants.WARN_BATCH_COUNT_SUCCESS, batchSize - notPowerError - outPowerError - checkError);
		result.put(WarnConstants.WARN_BATCH_COUNT_FAILED, notPowerError + outPowerError + checkError);
		batchMessageProcess(result);
		return result;
	}
	
	
	
	/***
	 * 流程信息查看
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("getAllProcessInfo.do")
	@ResponseBody
	public Map<String, Object> getAllProcessInfo(HttpServletRequest request) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		Map<String, Object> paramMap = new HashMap<String, Object>();
		List<HcpmsWarnProcessInfoDTO> list=new ArrayList<HcpmsWarnProcessInfoDTO>();
		// 获取参数
		String warnNo = request.getParameter("warnNo");
		String process = request.getParameter("status");
		paramMap.put("warnNo", warnNo);
		paramMap.put("process", process);
		list=hcpmsWarnService.getAllWorkFlowInfo(paramMap);
		result.put("dataList", list);
		result.put("status", hcpmsWarnService.queryProcessStatusInfo(paramMap));
		return result;
	}

}